package it.enea.xlab.validation;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.interceptor.Interceptors;

import schemavalidator.SchemaMainValidator;
import schemavalidator.SchemaMainValidatorImpl;
import validator.ErrorMessage;

@Stateless
@Interceptors({Profile.class})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ValidationManagerImpl implements ValidationManagerRemote {

	public XErrorMessage[] validation(String xmlRelPathFileName, String xsdURL) {

		XErrorMessage emListResult[] = null;
		
		//String validationArtifactsDir = PropertiesUtil.getArtifactsDirProperty();
		
		SchemaMainValidator smv = new SchemaMainValidatorImpl();
		smv.setRootDir("");

		try {

			System.out.println("AOOOOOOOOOO2!");
			
			ErrorMessage emList[] = smv.reportValidation(xmlRelPathFileName, xsdURL);
		
			emListResult = new XErrorMessage[emList.length];
			
			for (int i=0; i<emList.length; i++) {
				
				emListResult[i] = new XErrorMessage(emList[i].getErrorType(), emList[i].getLineNumber(), emList[i].getColNumber(), emList[i].getDescription());
			}
			
		} catch (Exception e) {
			emListResult = null;
		} 
		
		return emListResult;
	}

	public Long nothing() {
		
		System.out.println("AOOOOOOOOOO1!");
		return new Long(-1);
	}
	
}
